<?php
/**
 * Authenticate check for admin area
 *
 * <code>
 *  $username = "user";
 *  $realm = "admin";
 *  $password = md5('password');
 *  $passwordForFile = md5("$username:$realm:$password");
 * </code>
 *
 * @author Mario Schillermann <info@rockit-flash.com>
 * @encoding UTF-8 äöüßÖÄÜ
 * @copyright © 2011 Mario Schillermann (info@rockit-flash.com)
 * @license GNU GPL v2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
 * @package Page
 * @subpackage Index
 * @link $HeadURL$
 * @version SVN: $Id$
 * @phpVersion >=5
 * @todo
 */

class Admin_IndexController extends Zend_Controller_Action
{
    /**
     * Initialize the general options
     *
     * @return void
     */
    public function init()
    {
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
    }
    /**
     * Check the Identity
     *
     * @return void
     */
    public function indexAction()
    {
        $auth = Zend_Auth::getInstance();

        if ($this->getRequest()->path == 'logout') {
            // log out
            $auth->clearIdentity();
            // redirect to login form
            $this->_redirect('/de/admin');
        } else if ($auth->hasIdentity()) {
            // if user is already logged in, redirect to the desktop
            if (empty($this->getRequest()->path)) {

                $this->_forward('dashboard', 'desktop');
            } else {

                $this->_forward('index', 'app');
            }
        } else {
            // show login form
            $this->_forward('login', 'login');
        }
    }
}